import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MessageQuery, MessagePageResult, MessageForm } from "./types";

/**
 * 获取分页数据
 *
 * @param queryParams
 */
export function getMessagePage(
  queryParams?: MessageQuery
): AxiosPromise<MessagePageResult> {
  return request({
    url: "/admin/message/index",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取详情
 *
 * @param id
 */
export function getMessageForm(id: number): AxiosPromise<MessageDataForm> {
  return request({
    url: "/admin/message/edit",
    method: "get",
    params: { ids: id },
  });
}

/**
 * 添加
 *
 * @param data
 */
export function addMessage(data: MessageForm) {
  return request({
    url: "/admin/message/add",
    method: "post",
    data: data,
  });
}

/**
 * 更新
 *
 * @param id
 * @param data
 */
export function updateMessage(data: MessageForm) {
  return request({
    url: "/admin/message/edit",
    method: "put",
    data: data,
  });
}

/**
 * 批量删除，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteMessages(data: any) {
  return request({
    url: "/admin/message/del",
    method: "delete",
    data,
  });
}
